package com.woniuxy.orderServer.controller;


import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniuxy.commons.exception.orderLog.OrderLogException;
import com.woniuxy.commons.util.Result;
import com.woniuxy.orderServer.form.orderLog.OrderLogLoadForm;
import com.woniuxy.orderServer.model.OrderLog;
import com.woniuxy.orderServer.service.OrderLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 杜岷芫
 * @since 2024年03月20日
 */
@RestController
@RequestMapping("/orderLog")
@Api("订单日志")
public class OrderLogController {
    @Autowired
    private OrderLogService orderLogService;

    @ApiOperation("查询订单日志")
    @PostMapping("/load")
    public Result load(@RequestBody OrderLogLoadForm form ){
        if (ObjectUtil.isEmpty(form.getLogUser())) throw new OrderLogException(20001,"没有日志人");
        QueryWrapper<OrderLog> q = new QueryWrapper<>();
        q.eq("log_user",form.getLogUser());
        if (ObjectUtil.isNotEmpty(form.getOrderNum())) q.eq("order_num",form.getOrderNum());
        List<OrderLog> list = orderLogService.list(q);
        return Result.getListResult(OrderLog.class).setData(list).setMsg("成功");
    }

}

